//
//  FileUtilities.m
//  ContactViewerIos
//
//  Created by Mitchell Sans Souci on 3/26/12.
//  Copyright (c) 2012 Tiny Mission. All rights reserved.
//

#import "FileUtilities.h"

@implementation FileUtilities

+(void) writeData: (NSString*)data toFileInDocumentsDirectory: (NSString*)file
{
    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString* documentsDirectory = [paths objectAtIndex:0];
    NSString* outputFileName = [documentsDirectory stringByAppendingPathComponent:file];
    
    NSError* error;
    BOOL didNotFail = [data writeToFile:outputFileName atomically:YES encoding:NSUTF8StringEncoding error: &error];
    assert(didNotFail);
}

+(NSString*) readDataFromFileInDocumentsDirectory: (NSString*)file
{
    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString* documentsDirectory = [paths objectAtIndex:0];
    NSString* inputFileName = [documentsDirectory stringByAppendingPathComponent:file];

    NSError* error;
    NSString* data = [NSString stringWithContentsOfFile:inputFileName encoding:NSUTF8StringEncoding error:&error];
    return data;
}

@end
